<%-- 
  -- Body Edit para Student.
  --
  -- @author pablo.tortorella
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<script src="<html:rewrite page='/protected/script/util.js'/>" type="text/javascript"></script>

<%-- Para EXT --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/style/dragdrop.css'/>" id="styleFile"/>

<%-- prototype esta en el main layout --%>
<script src="<html:rewrite page='/protected/script/scriptaculous/scriptaculous.js'/>" type="text/javascript"></script>

<script type="text/javascript">
    function modify() {
		if (!validate()) {
			return;
		}
        var idObj = $("modifyId");        
        var nameObj = $("modifyNameId");
        var surnameObj = $("modifySurnameId");
        var selectedIdTypeObj = $("modifyIdTypeId");
        var personalIdObj = $("modifyPersonalIdId");
        var nationalityObj = $("modifyNationalityId");
        var emailObj = $("modifyEmailId");
        var email2Obj = $("modifyEmail2Id");
        var phoneObj = $("modifyPhoneId");
        var workPhoneObj = $("modifyWorkPhoneId");
        var mobileObj = $("modifyMobileId");
        var streetObj = $("modifyStreetId");
        var numberObj = $("modifyNumberId");
        var floorObj = $("modifyFloorId");
        var roomObj = $("modifyRoomId");
        var zipCodeObj = $("modifyZipCodeId");
        var cityObj = $("modifyCityId");
        var townObj = $("modifyTownId");
        var companyObj = $("modifyCompanyId");
        var positionObj = $("modifyPositionId");
        var degreeNameObj = $("modifyDegreeNameId");
        var universityObj = $("modifyUniversityId");
        var degreeYearObj = $("modifyDegreeYearId");
        var completeObj = $("modifyCompleteId");
        
        idObj.value = $("studentId").value;
        nameObj.value = $("nameId").value;
        surnameObj.value = $("surnameId").value;
        selectedIdTypeObj.value = $("selectedIdTypeId").value;
        personalIdObj.value = $("personalIdId").value;
        nationalityObj.value = $("nationalityId").value;
        emailObj.value = $("emailId").value;
        email2Obj.value = $("email2Id").value;
        phoneObj.value = $("phoneId").value;
        workPhoneObj.value = $("workPhoneId").value;
        mobileObj.value = $("mobileId").value;
        streetObj.value = $("addressStreetId").value;
        numberObj.value = $("addressNumberId").value;
        floorObj.value = $("addressFloorId").value;
        roomObj.value = $("addressRoomId").value;
        zipCodeObj.value = $("addressZipCodeId").value;
        cityObj.value = $("addressCityId").value;
        townObj.value = $("addressTownId").value;
        companyObj.value = $("companyId").value;
        positionObj.value = $("positionId").value;
        degreeNameObj.value = $("degreeNameId").value;
        universityObj.value = $("universityId").value;
        degreeYearObj.value = $("degreeYearId").value;
        completeObj.value = $("completeId").checked;
        var form = $("modifyStudentFormId");
        form.submit();
    }
    
    function validate() {
    	if (Util.valid.isBlank($("nameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el nombre. ');
            $("nameId").focus();
            return false;
        }
		if (Util.valid.isBlank($("surnameId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el apellido. ');
            $("surnameId").focus();
            return false;
        }
        if (Util.valid.isBlank($("personalIdId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el documento. ');
            $("personalIdId").focus();
            return false;
        }
        if (Util.valid.isBlank($("nationalityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la nacionalidad. ');
            $("nationalityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressStreetId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la calle. ');
            $("addressStreetId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressNumberId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el n&uacute;mero. ');
            $("addressNumberId").focus();
            return false;
        }
        else if (!$("addressNumberId").value.match(new RegExp("^[0-9. ]*$", "i"))) {
            Ext.MessageBox.alert('Error', 'El n&uacute;mero ingresado no es v&aacute;lido. ');
            $("addressNumberId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressCityId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la ciudad. ');
            $("addressCityId").focus();
            return false;
        }
        if (Util.valid.isBlank($("addressTownId").value)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la localidad. ');
            $("addressTownId").focus();
            return false;
        }
        if(!Util.valid.isBlank($("emailId").value) && !$("emailId").value.match(new RegExp("^.+@.+\\..+$", "i"))) {
            Ext.MessageBox.alert('Error', 'La direcci&oacute;n de email no es v&aacute;lida. ');
            $("emailId").focus();
            return false;
        }
        if(!Util.valid.isBlank($("email2Id").value) && !$("email2Id").value.match(new RegExp("^.+@.+\\..+$", "i"))) {
            Ext.MessageBox.alert('Error', 'La direcci&oacute;n de email alternativo no es v&aacute;lida. ');
            $("email2Id").focus();
            return false;
        }
        if(!Util.valid.isBlank($("degreeYearId").value) && !$("degreeYearId").value.match(new RegExp("^\\d+$", "i"))) {
            Ext.MessageBox.alert('Error', 'El a&ntilde;o de egreso debe ser num&eacute;rico. ');
            $("degreeYearId").focus();
            return false;
        }
        return true;
    }
    
    /* Lleva a listar las deudas de un participante
     */
    var listDebtsByStudent = function() {
        // Se saca del studentId y se lo pone en studentIdId del listDebtsByStudentFormId
        $("studentIdId").value = $("studentId").value;        
        
        var form = $("listDebtsByStudentFormId");
        form.submit();
    }
</script>

<div class="errors">
    <html:errors />
</div>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showStudent.do" styleId="studentFormId">
    <%-- Inyectados por Javascript --%>
    <html:hidden name="studentForm" property="id" styleId="studentId"/>

    <h2>Modificaci&oacute;n de participante</h2>
    
    <div class="studentEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nombres*
                </td>
                <td class="tableDataValue">
                    <html:text property="name" name="studentForm" styleId="nameId" size="45" maxlength="45" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Apellidos*
                </td>
                <td class="tableDataValue">
                    <html:text property="surname" name="studentForm" styleId="surnameId"size="45" maxlength="45" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tipo de documento
                </td>
                <td class="tableDataValue">
                    <html:select property="selectedIdType" styleClass="allSelects" styleId="selectedIdTypeId" >
                        <html:optionsCollection property="idTypeOptions"/>
                    </html:select>
                </td>            
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Documento*
                </td>
                <td class="tableDataValue">
                    <html:text property="personalId" name="studentForm" styleId="personalIdId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Nacionalidad*
                </td>
                <td class="tableDataValue">
                    <html:text property="nationality" name="studentForm" styleId="nationalityId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Particular
                </td>
                <td class="tableDataValue">
                    <html:text property="phone" name="studentForm" styleId="phoneId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Celular
                </td>
                <td class="tableDataValue">
                    <html:text property="mobile" name="studentForm" styleId="mobileId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Tel. Laboral
                </td>
                <td class="tableDataValue">
                    <html:text property="workPhone" name="studentForm" styleId="workPhoneId" size="25" maxlength="25" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email
                </td>
                <td class="tableDataValue">
                    <html:text property="email" name="studentForm" styleId="emailId" size="50" maxlength="75" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Email alternativo
                </td>
                <td class="tableDataValue">
                    <html:text property="email2" name="studentForm" styleId="email2Id" size="50" maxlength="75" />
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    Direcci&oacute;n
                </td>
                <td class="tableDataValue">
				 <table>
                	<tr>
	                	<td>
                    		Calle*
                    	</td>
                		<td>
                    		<html:text property="addressStreet" name="studentForm" styleId="addressStreetId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		N&uacute;mero*
                    	</td>
                		<td>
							<html:text property="addressNumber" name="studentForm" styleId="addressNumberId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Piso
                    	</td>
                		<td>
							<html:text property="addressFloor" name="studentForm" styleId="addressFloorId" />
                    	</td>
                	<tr>
                	<tr>
	                	<td>
                    		Departamento
                    	</td>
                		<td>
							<html:text property="addressRoom" name="studentForm" styleId="addressRoomId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		C&oacute;digo Postal
                    	</td>
                		<td>
							<html:text property="addressZipCode" name="studentForm" styleId="addressZipCodeId" size="8" maxlength="8" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Ciudad*
                    	</td>
                		<td>
							<html:text property="addressCity" name="studentForm" styleId="addressCityId" />
                    	</td>
                	</tr>
                	<tr>
	                	<td>
                    		Localidad*
                    	</td>
                		<td>
							<html:text property="addressTown" name="studentForm" styleId="addressTownId" />
                    	</td>
                	</tr>
                 </table>
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    Empresa
                </td>
                <td class="tableDataValue">
                    <html:text property="company" styleId="companyId" size="50" maxlength="50" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Cargo
                </td>
                <td class="tableDataValue">
                    <html:text property="position" styleId="positionId" size="50" maxlength="50" />
                </td>
            </tr>
            </tr><td class="tableDataTitle"></td><td class="tableDataValue"></td><tr>
            <tr>
                <td class="tableDataTitle">
                    T&iacute;tulo
                </td>
                <td class="tableDataValue">
                    <html:text property="degreeName" styleId="degreeNameId" size="50" maxlength="100" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Universidad
                </td>
                <td class="tableDataValue">
                    <html:text property="university" styleId="universityId" size="50" maxlength="50" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    A&ntilde;o de egreso
                </td>
                <td class="tableDataValue">
                    <html:text property="degreeYear" styleId="degreeYearId" size="4" />
                </td>
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Completo
                </td>
            	<td class="tableDataValue" colspan="2">
                	<html:checkbox property="complete" styleId="completeId" />
                </td>
            </tr>
        </table>
        
        <br/>
        <div id="clear"></div>
    	<p class="mensajeCamposObligatorios">Los campos marcados con un asterisco (*) son obligatorios.</p>
    	<div id="clear"></div>
        
        <%-- Solo los administradores pueden modificar un participante, pero verlo, pueden todos --%>
        <security:securizedContent roles="administrador,secretaria,ente">
            <div class="panelButton">
                <input type="button" value="Modificar" onclick="modify();" title="Ver datos del participante..." class="button">
            
                <%-- Las deudas del participante solo las pueden ver los administradores o la secretaria --%>
                <security:securizedContent roles="administrador,secretaria">
                    <input type="button" value="Ver Deudas" onclick="listDebtsByStudent();" title="Ver las deudas del participante ..." class="button">
                </security:securizedContent>

            </div>  
        </security:securizedContent>
    
    </div>

</html:form>


<%-- Inyectados por Javascript --%>
<div id="modifyDivId" class="hideClass">
    <html:form action="/protected/modifyStudent" styleId="modifyStudentFormId">
        <html:hidden property="id" value="" styleId="modifyId" />
        <html:hidden property="name" value="" styleId="modifyNameId" />
        <html:hidden property="surname" value="" styleId="modifySurnameId" />
        <html:hidden property="selectedIdType" value="" styleId="modifyIdTypeId" />
        <html:hidden property="personalId" value="" styleId="modifyPersonalIdId" />
        <html:hidden property="nationality" value="" styleId="modifyNationalityId" />
        <html:hidden property="email" value="" styleId="modifyEmailId" />
		<html:hidden property="email2" value="" styleId="modifyEmail2Id" />
        <html:hidden property="phone" value="" styleId="modifyPhoneId" />
        <html:hidden property="workPhone" value="" styleId="modifyWorkPhoneId" />
        <html:hidden property="mobile" value="" styleId="modifyMobileId" />
        <html:hidden property="addressStreet" value="" styleId="modifyStreetId" />
        <html:hidden property="addressNumber" value="" styleId="modifyNumberId" />
        <html:hidden property="addressFloor" value="" styleId="modifyFloorId" />
        <html:hidden property="addressRoom" value="" styleId="modifyRoomId" />
        <html:hidden property="addressZipCode" value="" styleId="modifyZipCodeId" />
        <html:hidden property="addressCity" value="" styleId="modifyCityId" />
        <html:hidden property="addressTown" value="" styleId="modifyTownId" />
        <html:hidden property="company" value="" styleId="modifyCompanyId" />
        <html:hidden property="position" value="" styleId="modifyPositionId" />
        <html:hidden property="degreeName" value="" styleId="modifyDegreeNameId" />
        <html:hidden property="university" value="" styleId="modifyUniversityId" />
        <html:hidden property="degreeYear" value="" styleId="modifyDegreeYearId" />
        <html:hidden property="complete" value="" styleId="modifyCompleteId" />
    </html:form>
</div>

<%-- Inyectados por Javascript. Es para listar las deudas --%>
<div id="listDebtsByStudentDiv" class="hideClass">
    <html:form action="/protected/listDebtsByStudent" styleId="listDebtsByStudentFormId">
        <html:hidden property="studentId" value="" styleId="studentIdId" />
    </html:form>
</div>
